<template>
  <div class="footprint">
    <scroll class="scroll-wrapper" :data="historyGoods">
      <div>
        <div class="footprint-list" v-for="item in historyGoods">
          <div class="date-title">{{item.date}}</div>
          <div class="footprint-item" v-for="(good,index) in item.goodsList">
            <div class="goods-img">
              <img style="width: 1.1rem;height: 1.1rem;" :src="good.thumb_url" alt="">
            </div>
            <div class="goods-info">
              <div class="goods-name">{{good.goods_name}}</div>
              <div class="goods-count">{{good.sales_tip}}</div>
              <div class="goods-price">￥{{good.price/100}}</div>
            </div>
            <div class="footprint-item-goods-line" :class="{lastItem:index===item.goodsList.length-1}"></div>
          </div>
        </div>
      </div>
    </scroll>
  </div>
</template>

<script>
import axios from "axios";
import scroll from "../../../common/scroll";
import { getfootprint } from "../../../api/getDatas";
export default {
  components: {
    scroll
  },
  data() {
    return {
      historyGoods: null,
      flag: true
    };
  },
  methods: {
    initData() {
      getfootprint().then(res => {
        this.goodsList = res.data.data.goods_list;
        let footprintItems = [];
        this.goodsList.forEach(el => {
          var date = new Date(el.browse_time * 1000);
          let d = date.getMonth() + 1 + "月" + date.getDate() + "日";
          let footprintItem = { date: d, goods: el };
          footprintItems.push(footprintItem);
        });
        let newData = [];
        footprintItems.forEach(el => {
          let indexFound = newData.findIndex(
            newItem => newItem.date === el.date
          );
          if (indexFound > -1) {
            newData[indexFound].goodsList.push(el.goods);
          } else {
            newData.push({
              date: el.date,
              goodsList: [el.goods]
            });
          }
        });
        this.historyGoods = newData;
      });
    }
  },
  created() {
    this.initData();
  }
};
</script>

<style lang="less" scoped>
.footprint {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  .scroll-wrapper {
    height: 100%;
    overflow: hidden;
  }
}
.footprint-list {
  //   background-color: white;
  .date-title {
    display: flex;
    align-items: center;
    color: #9c9c9c;
    font-size: 0.14rem;
    height: 0.34rem;
    padding-left: 0.1rem;
    background-color: white;
    border-top: 1px solid #ededed;
  }
  .footprint-item {
    display: flex;
    height: 1.29rem;
    width: 100%;
    position: relative;
    background-color: #fff;
    align-items: center;
    .footprint-item-goods-line {
      position: absolute;
      bottom: 0;
      left: 1.21rem;
      border-bottom: 1px solid #ededed;
      width: 100%;
      line-height: 0;
      height: 0;
    }
    .lastItem {
      border: none;
    }
    .goods-info {
      margin-left: 0.1rem;
      height: 1.1rem;
      .goods-name {
        color: #151516;
        font-size: 0.15rem;
        line-height: 0.2rem;
        vertical-align: bottom;
        max-height: 0.4rem;
        overflow-y: hidden;
      }
      .goods-count {
        color: #9c9c9c;
        font-size: 0.12rem;
        margin-top: 0.25rem;
      }
      .goods-price {
        max-width: 2rem;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
        color: #e02e24;
        line-height: 0.19rem;
        font-size: 0.18rem;
        white-space: nowrap;
        position: absolute;
        font-weight: 700;
        height: 0.2rem;
        margin-top: 0.1rem;
        margin-left: -0.02rem;
      }
    }
  }
}
</style>
